<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Hello, world!</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../css/font-awesome.min.css">
    <link rel="stylesheet" href="../fonts/iconfont.css">
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/bootstrap-select.min.css">
    <link rel="stylesheet" href="../css/select2.min.css">
    <link rel="stylesheet" href="../css/select2-bootstrap4.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style>
        .bd-placeholder-img {
            font-size: 1.125rem;
            text-anchor: middle;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        @media (min-width: 768px) {
            .bd-placeholder-img-lg {
                font-size: 3.5rem;
            }
        }

        html,
        body {
            height: 100%;
        }

        body {
            padding-bottom: 40px;
            background-color: #fff;
        }

        .form-signin {
            width: 100%;
            max-width: 640px;
            margin: auto;
            padding: 15px;
        }

        .form-signin .checkbox {
            font-weight: 400;
        }

        .form-signin .form-control {
            position: relative;
            box-sizing: border-box;
            height: auto;
            padding: 10px;
            font-size: 16px;
        }

        .form-signin .form-control:focus {
            z-index: 2;
        }

        .form-signin input[type="email"] {
            margin-bottom: -1px;
            border-bottom-right-radius: 0;
            border-bottom-left-radius: 0;
        }

        .form-signin input[type="password"] {
            margin-bottom: 10px;
            border-top-left-radius: 0;
            border-top-right-radius: 0;
        }

        .sr-only2 {
            margin-top: 15px;
        }


        .logodiv img {
            width: 240px;
            margin: 0 auto;
            display: block;
        }

        .logodiv {
            text-align: center;
        }

        .logodiv h1 {
            font-size: 1.4rem;
            color: #03357a;
            margin-top: 20px;
            margin-bottom: 20px;
        }
        
        .logodiv h2 {
            font-size: 1.5rem;
            margin-bottom: 80px;
        }



        .fgtpaws {
            text-align: center;
            margin-top: 10px;
        }

        .btn {
            padding: 0.375rem 0.15rem
        }

        .btn-tiqu {
            width: 125px;
            margin: 0 auto;
            display: block;
        }

        .buytitle {
            font-size: 1.1rem;
            color: #03357a;
            margin-top: 20px;
        }

        .buytitle span {
            font-size: 1rem;
            color: #999;
        }
        .action-row button {
            margin-bottom: 15px;
        }

        .buysearch {
            font-size: smaller;
        }

        .formscreen .form-control-theme {
            font-size: smaller;
        }

        .action-row {
            position: fixed;
            width: 100%;
            bottom: 0;
            margin-top: 0;
            margin-bottom: 0;
            background: #fff;
            left: 0;
        }
        .wareContent{
            display: flex;
            justify-content: center;
            align-items: center;
            position: relative;
        }
        .container2 {
            padding: 10px 25px;
            display: block;
            overflow: hidden;
        }
        .lineCss{
            width: 90%;
            margin: 0 auto;
            font-size: 0.8rem;
            padding: 20px 20px;
            
        }
        .lineBorder{
            width: 90%;
            margin: 0 auto;
            font-size: 0.8rem;
            padding: 20px 20px;
            border-bottom: 1px solid #000;
        }
        .bootstrap-select {
            width: calc(100% - 0px) !important;
        }
        .item-border{
            border-bottom: 1px solid #ced4da;
            margin-bottom: 2px;
        }
        .form-control-theme{
            border: none !important;
            border-bottom: none !important;
        }

        .formscreen .filter-option-inner-inner {
            font-size: smaller;
        }
        .form-select{
            background-color: transparent !important;
        }
        .myselect {
            width: calc(100% - 0px);
        }

        .btn-action:disabled {
            background: #D9D9DA !important;
            color: #808081 !important;
        }

        .buysearch {
            width: 100%;
            display: block;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="container2">
            <div class="logodiv">
                <img class="bannerlogo pt-3" src="../image/logo.jpeg">
            </div>
            <div class="row  align-items-center">
                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh  flex-shrink-0 filedlabel">{{lan['Issue_Date']}}
                        </div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <input type="date" v-model="searchdata.ArrivedDate"
                                :disabled="searchdata.Lot_btn"
                                placeholder="Please Enter Issue Date(Required)"
                                class="form-control form-control-theme" value="">
                        </div>
                    </div>
                </div>
                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Part']}}</div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="wareContent">
                                <input
                                @blur="blurPartNumInfo"
                                :disabled="searchdata.Lot_btn"
                                type="text"
                                v-model="searchdata.PartNum"
                                class="form-control form-control-theme" value="">
                            </div>

                        </div>
                    </div>
                </div>
                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Desc']}}</div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="wareContent">
                                <input
                                type="text"
                                disabled
                                v-model="searchdata.PartDescription"
                                class="form-control form-control-theme" value="">
                            </div>

                        </div>
                    </div>
                </div>
                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['WareHouseCode']}}
                        </div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="wareContent">
                                <input   v-if="!searchdata.warehouseFlag" type="text"
                                v-model="searchdata.WarehouseCode"
                                @click="warehouseFocus()"
                                :disabled="searchdata.Lot_btn"
                                class="form-control form-control-theme" value="">

                                <select  v-if="searchdata.warehouseFlag" v-model="searchdata.WarehouseCode" id="vendorselect"
                                :placeholder="lan['WareHouseCode_placeholder']"
                                @change="waerChange()"
                                class="form-select myselect myselect1 form-control-theme"
                                data-live-search="true">
                                    <option v-for="(item,index) in WareHouseCodeList" :key="index"
                                    :data-num="item.Warehse_WarehouseCode" :value="item.Warehse_WarehouseCode"
                                    :data-name="item.Warehse_Description" :data-tokens="item.Warehse_WarehouseCode">
                                    {{item.Warehse_Description}}</option>
                                </select>
                                <i v-if="!searchdata.warehouseFlag" style="margin-left: 5px;" @click="onWareQuery()" class="iconfont icon-scan"></i>
                                <i v-if="searchdata.warehouseFlag" style="margin-left: 5px;" @click="onWareScan()" class="iconfont icon-query"></i>

                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['BinNum']}}</div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="wareContent">
                                <input   v-if="!searchdata.binFlag" type="text"
                                @click="binFocus()"
                                :disabled="searchdata.Lot_btn"
                                v-model="searchdata.BinNum"
                                class="form-control form-control-theme" value="">
                                <select v-if="searchdata.binFlag" v-model="searchdata.BinNum" id="vendorselect2"
                                @change="binChange()" 
                                :disabled="receipt_btn"
                                class="form-select myselect myselect2 form-control-theme"
                                data-live-search="true" :placeholder="lan['BinNum_placeholder']">
                                <option v-for="(item,index) in BinNumList" :key="index" :data-num="item.WhseBin_BinNum"
                                    :value="item.WhseBin_BinNum" :data-name="item.WhseBin_Description"
                                    :data-tokens="item.WhseBin_BinNum">
                                    {{item.WhseBin_Description}}</option>
                                </select>
                                <i  v-if="!searchdata.binFlag" style="margin-left: 5px;" @click="onBinQuery()" class="iconfont  icon-scan"></i>
                                <i  v-if="searchdata.binFlag" style="margin-left: 5px;" @click="onBinScan()" class="iconfont icon-query"></i>

                            </div>
                            
                        </div>
                    </div>
                </div>
                <div v-if="searchdata.is_Lot" class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel" style="word-wrap: break-word;">{{lan['Lot']}}</div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="wareContent">
                                <input  type="text"
                                style="width: 40%;"
                                v-if="searchdata.lotFlag"
                                @blur="lotBlur()"
                                :disabled="!searchdata.is_Lot || searchdata.Lot_btn"
                                v-model="searchdata.LotNum"
                                class="form-control form-control-num" value="">
                                <input  type="text"
                                style="width: 40%;"
                                v-if="!searchdata.lotFlag"
                                :disabled="!searchdata.is_Lot || searchdata.Lot_btn"
                                @click="lotFocus()"
                                v-model="searchdata.LotNum"
                                class="form-control form-control-num" value="">
                                <i  v-if="!searchdata.lotFlag" style="margin-left: 5px;" @click="onLotQuery()" class="iconfont  icon-scan"></i>
                                <i  v-if="searchdata.lotFlag" style="margin-left: 5px;" @click="onLotScan()" class="iconfont icon-query"></i>
                                <button 
                                style="padding-left: 2px;padding-right: 2px;margin-left: 5px; width: 110px;"
                                type="button" @click="GenerateNewLotNum()"
                                :disabled="searchdata.Lot_btn"
                                class="btn btn-primary btn-sm">{{lan['GetLotNum']}} </button>
                                <button 
                                    style="padding-left: 2px;padding-right: 2px;margin-left: 5px; width: 90px;"
                                    type="button" 
                                    :class=" (Batch_check || exist_btn) ? 'btn-secondary':'btn-primary'"
                                    :disabled="Batch_check || searchdata.Lot_btn || exist_btn" 
                                    @click="BatchProperties();"
                                    class="btn   btn-sm"
                                    >{{lan['Batch_Properties']}}
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel" style="word-wrap: break-word;">{{lan['Qty_Ament']}}</div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="wareContent">
                                <input type="number" 
                                @blur="NumBlur()"
                                v-model="searchdata.OnhandQty" class="form-control form-control-theme" :disabled="searchdata.Lot_btn"
                                value="">
                                <input 
                                v-if="searchdata.IUM"
                                style="width: 40px;margin-left: 10px;text-align: center;"
                                type="text" 
                                v-model="searchdata.IUM" class="form-control form-control-theme"
                                value="">
                              
                            </div>
                            
                        </div>
                    </div>
                </div>
                <div v-if="searchdata.is_SerialNum" class="col-12">
                    <div class="d-flex bd-highlight align-items-center">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Generate_SN']}}</div>
                        <div class="p-2 flex-grow-1 bd-highlight">
                            <div class="row">
                                <div class="col-6">
                                    <button v-if="searchdata.is_SerialNum" :disabled="(app.searchdata.SNBaseDataType == 'MASK' && app.searchdata.MaskType == 0) || app.searchdata.SNBaseDataType == 'CHARACTER' || app.searchdata.entryCheck  || num_btn"
                                     @click="CreateSeren()" type="button" tapmode=""
                                    :class=" searchdata.is_SerialNum == false ? 'btn-secondary':'btn-primary'"
                                    class="btn  btn-action  btn-block">{{lan['Generate_SN']}} <span
                                    class="badge badge-light">{{searchdata.SerialNum.length}}</span></button>
                                </div>
                                <div class="col-6">
                                    <button v-if="searchdata.is_SerialNum"  type="button" tapmode="" @click="toSerial()" :disabled="(app.searchdata.SNBaseDataType == 'MASK' && app.searchdata.MaskType == 1) || app.searchdata.createCheck"
                                    :class=" searchdata.is_SerialNum == false ? 'btn-secondary':'btn-primary'"
                                    class="btn btn-action  btn-block">{{lan['Serial_No']}}
                                    </button>
                                </div>
                            </div>
                            <!--                                        
                            <select :disabled="is_SerialNum==0" id="site-content" v-model="searchdata.is_sn" class="form-select form-control-theme form-control"
                                :placeholder="lan['Site_placeholder']" aria-label="Please select site">
                                <option value="1">{{lan['YES']}}</option>
                                <option value="0">{{lan['NO']}}</option>
                            </select> -->
                        </div>
                    </div>
                </div>
                <div class="col-12">
                    <div class="d-flex bd-highlight align-items-center item-border">
                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['REASON_CODE']}}</div>
                        <div  class="p-2 flex-grow-1 bd-highlight">
                            <div v-if="!searchdata.Lot_btn">
                                <select v-model="searchdata.ReasonCode"
                                id="reasonSelect"
                                class="form-select myselect myselect3 form-control-theme"
                                data-live-search="true" :placeholder="lan['BinNum_placeholder']">
                                <option v-for="(item,index) in reason" :key="index" :data-num="item.ReasonCode"
                                    :value="item.ReasonCode" :data-name="item.Description">
                                    {{item.Description}}</option>
                                </select>
                            </div>
                            <div  v-if="searchdata.Lot_btn">
                                <input 
                                    type="text" 
                                    disabled
                                    v-model="searchdata.Description" class="form-control form-control-theme"
                                    value="">
                               
                            </div>
                                                                    
                        </div>
                            
                    </div>
                </div>

            </div>
            <div class=" row justify-content-center" style="padding: 20px 0;">
                <div style="padding-left: 5px;padding-right: 5px;" class="col-3 col-md-3">
                    <button type="button" :disabled="receipt_btn" onclick="checksubmit();" tapmode=""
                        class="btn btn-primary btn-action">{{lan['Comfirm']}}</button>
                </div>
                <div style="padding-left: 5px;padding-right: 5px;" class="col-3 col-md-3">
                    <button type="button" @click="print_label();" :disabled="print_btn" tapmode=""
                        class="btn btn-primary btn-action">{{lan['Print_Label']}}
                    </button>
                </div>
                <div style="padding-left: 5px;padding-right: 5px;" class="col-3 col-md-3">
                    <button type="button" :disabled="print_btn" onclick="resetSubmit();" tapmode=""
                        class="btn btn-primary btn-action">{{lan['Reset']}}
                    </button>
                </div>
                <div style="padding-left: 5px;padding-right: 5px;" class="col-3 col-md-3">
                    <button type="button" tapmode="" onclick="close_win1()"
                        class="btn btn-primary btn-action">{{lan['Cancel']}}</button>
                </div>

            </div>
            <div>
                <div class="copyright">
                    <div class="row" :gutter="10">
                        <div  class="col-5" style="text-align: right;">{{lan['Version']}}：</div>
                        <div  class="col-7">{{appversion}}</div>
                        <div  class="col-5"  style="text-align: right;">{{lan['Site']}}：</div>
                        <div  class="col-7">{{SiteName}}</div>
                        <div  class="col-5"  style="text-align: right;">{{lan['Company']}}：</div>
                        <div  class="col-7">{{CompanyName}}</div>
                    </div>
                </div>
            </div>
        
        </div>
    </div>

</body>
<script type="text/javascript" src="../script/lang.js"></script>
<script type="text/javascript" src="../script/model.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/vue.min.js"></script>
<script type="text/javascript" src="../script/jquery.min.js"></script>
<script type="text/javascript" src="../script/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="../script/bootstrap-select.min.js"></script>
<script type="text/javascript" src="../script/select2/select2.min.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
    var postcount = 0;
    var tagspostcount = 0;
    var returncount = 0;
    var model_show = 1;
    var postlist = [];
    var tags = [];
    const app = new Vue({
        el: '#app',
        data: {
            lineCss:"lineCss",
            lineBorder:'lineBorder',
            list: [],
            newList:[],
            screenwidth: document.body.clientWidth,
            house: [],
            bin: [],
            WareHouseCodeList:[],
            BinNumList:[],
            reason:[],
            BinNum: "",
            searchdata: {
                name: '',
                PartDescription:'',
                PartNum:'',
                WarehouseCode:'',
                BinNum:'',
                ArrivedDate: timenow(),
                PackageID: '',
                LotNum:'',
                OnhandQty:'',
                oldQty:'',
                IUM:'',
                is_Lot:false,
                is_SerialNum:false,
                SerialNum:[],
                lotFlag:false,
                binFlag:false,
                warehouseFlag:false,
                ReasonCode:'',
                Description:'',
                SNPrefix:'',
                SNFormat:'',
                SNBaseDataType:'',
                MaskType:'',
                data:{},
                Lot_btn:false,
                PartClass_NegQtyAction:"",
                MaxQty:"",
                NumOfDec:"",
                createCheck:false,
                entryCheck:false,
            
            },
            LotItem:{},
            Batch_check:false,
            exist_btn:false,
            attribute_btn:false,
            uinfo: {},
            lotinfo: {},
            create_btn: false,
            receipt_btn: true,
            print_btn: true,
            print_num: '',
            hasError: false,
            num_btn:false
        },
        mounted() {
            const that = this
            window.onresize = () => {
                return (() => {
                    that.screenwidth = document.body.clientWidth
                })()
            }
        },
        methods: {
            NumBlur(){
               if(app.searchdata.OnhandQty < 0){
                   app.num_btn = true
                }else{
                    app.num_btn = false
                }
            },
            toSerial: function () {
                console.log(JSON.stringify(this.searchdata),1111111)
                if(!this.searchdata.OnhandQty){
                    api.toast({
                        msg: lan['palase_enter'] + lan['Qty_Ament'],
                        location: 'middle'
                    });
                    return;
                }
                var data = {};
                if(this.searchdata.SerialNum.length == 0 || this.searchdata.oldQty != this.searchdata.OnhandQty){
                    this.searchdata.SerialNum = []
                    var InputOurQty = Math.abs(processNumber(this.searchdata.OnhandQty, app.searchdata.NumOfDec));
                    for (let i = 0; i < InputOurQty; i++) {
                        this.searchdata.SerialNum.push({
                            'type': i+1,
                            'SerialNumber': '',
                        })
                    }
                    app.searchdata.entryCheck = true;
                }
                data.post = this.searchdata;
                data.index = 0;
                data.SNFormat = app.searchdata.SNFormat;
                data.SNPrefix = app.searchdata.SNPrefix;
                data.SNBaseDataType = app.searchdata.SNBaseDataType;
                data.MaskType = app.searchdata.MaskType;
                data.searchdata = this.searchdata;
                data.title = lan['Quantity_Adjustments'];
                data.frame = "sn_qty";
                data.right = [{
                    text: lan["Scan"],
                    color: '#fff',
                }];
                console_debug(data,"sn_qty_update");

                openNavWin2(data.frame, data);

            },
            CreateSeren(){
                let  InputOurQty = Math.abs(processNumber(this.searchdata.OnhandQty, app.searchdata.NumOfDec));
                if(!InputOurQty){
                    api.toast({
                        msg: lan['Please_enter_Qty'],
                        location: 'middle'
                    });
                    return false;
                }
                if (ajaxing) { return; } showProgress(lan['Loading']);
                var that = this;
                var data1 = {
                    "CompanyID": userinfo.Company,
                    "PlantID": userinfo.Site,
                    "UserName": userinfo.Name,
                    "Password": userinfo.password,
                    "TranDate":app.searchdata.ArrivedDate,
                    "TranQty":InputOurQty,
                    "PartNum":app.searchdata.PartNum 
                }
                api.ajax({
                    url: wmsserver + 'sninvqtyadj/',
                    method: 'post',
                    returnAll: false,
                    headers: {
                        'token': wmstoken,
                        'Content-Type': 'application/json;charset=utf-8'
                    },
                    //dataType: 'text',
                    data: {
                        body: create_submit_data(data1)
                    }
                    //data: {values: data1}
                }, function (ret, err) {
                    ajaxing = 0;
                   console.log(JSON.stringify(ret),3333333)
                    hideProgress();
                    if (ret && ret.code == 1) {
                        that.searchdata.createCheck = true
                        that.searchdata.SerialNum = ret.data.SelectedSerialNumbers;
                        that.searchdata.oldQty = processNumber(that.searchdata.OnhandQty, that.searchdata.NumOfDec)
                        setTimeout(function(){
                            that.toSerial()
                        },200)
                     
                    } else {
                        hideProgress();
                        errMassage(ret.msg)
                    }

                });
            },
            print_label: function () {
                var btns = [];
                btns.push(lan['Print_Carton_Label']); //箱条码
                if(app.searchdata.SerialNum.length > 0){
                    btns.push(lan['Print_SN_Label']);
                }
                var that = this;
                api.actionSheet({
                    title: lan['Tips'],
                    cancelTitle: lan['Cancel'],
                    buttons: btns
                }, function (ret, err) {
                    var index = ret.buttonIndex;
                    var key = index - 1;

                    if (btns[key] == lan['Print_Carton_Label']) {

                        print_type = 2;
                        that.print_carton();
                    }

                    if (btns[key] == lan['Print_SN_Label']) {
                        print_type = 1;
                        that.submit_sncode();
                    }
                });
            },
            async print_carton() {
                showProgress(lan['Loading']);
                print_tags = [];
                let ExpiryDate = ""
                console.log(JSON.stringify(this.goodlist),33333)
                let item={
                    LabelNum:this.searchdata.PartNum + "/" + app.searchdata.LotNum,
                    PartNum:this.searchdata.PartNum,
                    PartDescription:this.searchdata.PartDescription,
                    OnhandQty:this.searchdata.OnhandQty,
                    LotNum:this.searchdata.LotNum,
                    IUM:this.list[0].IUM
                }
                print_tags.push(item);
                hideProgress();
                if (print_tags.length > 0) {
                    open_printpage2(print_tags, 1, 1, 2,0);
                } else {
                    api.toast({
                        msg: lan['No_Data_Submit'],
                        location: 'middle'
                    });
                }
            },
            submit_sncode: function () {
                print_index = 0;
                print_tags = [];

                print_tags = this.searchdata.SerialNum;
                if (this.searchdata.OrderNum != '') {
                    this.searchdata[0].OrderNum = this.searchdata.OrderNum;
                }
                for(let i in print_tags){
                    print_tags.LotNum = this.searchdata.LotNum;
                    print_tags.IUM = this.searchdata.IUM;
                }
                open_printpage(print_tags, 1, 3);
            },
            BatchProperties:function(){
                let that = this
                let PartNum = that.searchdata.PartNum;
                let LotNum =  that.searchdata.LotNum;
                if(!LotNum){
                    api.toast({
                        msg:lan['Please_Lot_nunber'],
                        location: 'middle'
                    });
                    return
                }
                if(PartNum != '' && LotNum != ''){
                    var data = {};
                    data.item = app.LotItem;
                    data.PartNum = PartNum;
                    data.LotNum = LotNum;
                    data.attribute_btn = app.attribute_btn
                    data.Lot_btn = app.searchdata.Lot_btn;
                    data.title = lan['Batch_Properties'];
                    data.frame = "batch_properties";
                    openNavWin2(data.frame, data);
                }
            },
            onWareQuery(){
                app.searchdata.warehouseFlag = true;
            },
            onWareScan(){
                app.searchdata.warehouseFlag = false;
            },
            onBinQuery(){
                app.searchdata.binFlag = true;
            },
            onBinScan(){
                app.searchdata.binFlag = false;
            },
            lotFocus:function(){
                scan1()
            },
            warehouseFocus:function(){
                scan2()
            },
            binFocus:function(){
                scan3()
            },
            blurPartNumInfo(){
                const value = this.searchdata.PartNum;
                getPartNumInfo(value)
            },
            lotBlur:function(){
                setTimeout(function(){
                    loadOnhandData()
                },300)
            },
            GenerateNewLotNum: function () {

                var model = {
                    "vPartNum": app.searchdata.PartNum
                }
                var that = this;

                api.ajax({
                    url: server + 'Erp.BO.LotSelectUpdateSvc/GenerateNewLotNum',
                    method: 'post',
                    returnAll: false,
                    headers: {
                        'Authorization': userinfo.Token,
                        'Content-Type': 'application/json;charset=utf-8'
                    },
                    data: {
                        body: JSON.stringify(model)
                    }
                }, function (ret, err) {
                    ajaxing = 0;
                    console_debug(ret, err);
                    console.log(JSON.stringify(model),22222)
                    console.log(JSON.stringify(ret),111111)
                    hideProgress();
                    if (ret) {
                        app.searchdata.LotNum = ret.parameters.vNewLotNum
                        // that.LotSelectUpdate(index);
                    } else {
                        api.toast({
                            msg: lan['TrackLots_Error'],
                            location: 'middle'
                        });
                    }

                });


            },
            onLotQuery(){
                app.searchdata.lotFlag = true;
            },
            onLotScan(){
                app.searchdata.lotFlag = false;
            },
          
            waerChange:function(){
                loadBinData(this.searchdata.WarehouseCode)
            },
            binChange:function(){
                setTimeout(function(){
                    loadOnhandData()
                },300)
            }
           
        }
    });
    apiready = function () {
        api.parseTapmode();
        server = getapi();
        api.addEventListener({ name: 'navitembtn' }, function (ret, err) {
            if (ret.type == 'left') { close_win1(); }
            if (ret.type == 'right') { scan(); }

        });
        app.vendors = get_prefs_data("Vendors");
        app.house = get_prefs_data("WarehouseCode");
        console.log(JSON.stringify(app.house),55555)
        app.uinfo = get_user_info();
        userinfo = get_user_info();
        app.searchdata.name = userinfo.Name;
        api.addEventListener({
            name: 'batch_properties_update'
        }, function (ret, err) {
            if (ret && ret.value) {
                var snposts1 = ret.value;
                console.log(JSON.stringify(snposts1), 55555)
                app.searchdata.Lot_btn = snposts1.Lot_btn
                app.attribute_btn = snposts1.attribute_btn
                api.closeWin({ name: 'batch_properties' });
            }
        });
        setTimeout(function () {
            init_select2();
            init_select();
        }, 200);
        
        api.addEventListener({
            name: 'sn_qty_update'
        }, function (ret, err) {
            if(ret && ret.value){
                var snposts = ret.value;
                console.log(JSON.stringify(snposts),33333)
                app.searchdata.OnhandQty = snposts.OnhandQty;
                app.searchdata.oldQty = snposts.oldQty;
                if(app.searchdata.OnhandQty > 0){
                    app.searchdata.SerialNum = snposts.SerialNum;
                    app.searchdata.data = snposts.data
                }else{
                    app.searchdata.SerialNum = snposts.SerialNum;
                }
               
                console.log(JSON.stringify(app.searchdata),44444)
                api.closeWin({name: 'sn_qty_update'});
            }
        });
        api.addEventListener({
            name: 'infrared_scanning'
        }, function (ret, err) {
            console.log(JSON.stringify(ret));
            if (ret && ret.value && ret.value.str && is_scan == 0) {
                app.searchdata.PartNum = ret.value
                getPartNumInfo(ret.value)
            }

        });
        api.addEventListener({
            name: 'keyback',
            extra: {
                slidBackIntercept: true    
            }
        }, function (ret, err) {
            close_win1()
        });
    }
    function scan1(){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.searchdata.LotNum = ret.content;
                    setTimeout(function(){
                        loadOnhandData()
                    },300)
                }
            } 
        });
          
    }

    function resetSubmit(){
        app.searchdata.PartDescription='';
        app.searchdata.PartNum='';
        app.searchdata.WarehouseCode='';
        app.searchdata.BinNum='';
        app.searchdata.LotNum='';
        app.searchdata.OnhandQty='';
        app.searchdata.oldQty='';
        app.searchdata.IUM='';
        app.searchdata.SerialNum=[];
        app.searchdata.lotFlag=false;
        app.searchdata.binFlag=false;
        app.searchdata.warehouseFlag=false;
        app.searchdata.ReasonCode='';
        app.searchdata.data={};
        app.searchdata.Description = "";
        app.searchdata.Lot_btn=false;
        app.receipt_btn = false;
        app.print_btn = true;
        app.attribute_btn = false;
        app.searchdata.createCheck = false;
        app.searchdata.entryCheck = false;
        app.num_btn = false
        $('.myselect3').selectpicker('destroy');//在更新
        setTimeout(function(){
            $('.myselect3').selectpicker('refresh');//在更新
            $('.myselect4').selectpicker('destroy');//在更新
        },200)

    }
    
    function scan2(){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.searchdata.WarehouseCode = ret.content;
                    loadBinData(this.searchdata.WarehouseCode)
                }
            } 
        });
    }
    function scan3(){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.searchdata.BinNum = ret.content;
                    setTimeout(function(){
                        loadOnhandData()
                    },300)
                }
            } 
        });
          
    }
    function getPartNumInfo(data){
        userinfo = get_user_info();
        var filter = "?CompID=" + userinfo.Company  + "&Site=" + userinfo.Site;
        filter += "&PartNum=" + data ;
        api.ajax({
            url: server + 'BaqSvc/WMS_PartInfo/' + filter,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {}  
        }, function (ret, err) {
            ajaxing = 0;
            is_scan = 0;
            console.log(JSON.stringify(ret),44444)
            hideProgress();
            if (ret && ret.value.length>0) {
                let newList = init_list(ret.value)
                console.log(JSON.stringify(newList),111111)
                app.searchdata.PartNum = newList[0].PartNum;
                app.searchdata.PartDescription = newList[0].PartDescription;
                app.searchdata.WarehouseCode = newList[0].WarehouseCode;
                app.searchdata.BinNum = newList[0].BinNum;
                app.searchdata.is_SerialNum = newList[0].Part_TrackSerialNum;
                app.searchdata.is_Lot = newList[0].Part_TrackLots;
                app.searchdata.IUM = newList[0].Part_IUM;
                app.searchdata.SNPrefix = newList[0].Part_SNPrefix;
                app.searchdata.SNFormat = newList[0].Part_SNFormat;
                app.searchdata.SNBaseDataType = newList[0].Part_SNBaseDataType;
                app.searchdata.MaskType = newList[0].SerialMask_MaskType;
                app.searchdata.NumOfDec = newList[0].UOM_NumOfDec;
                app.searchdata.PartClass_NegQtyAction = newList[0].PartClass_NegQtyAction
                LotAttributeOption()
                // return;
                for (i in newList){
                    var ret1 = [];
                    ret1.push(newList[i]);
                    app.list = app.list.concat(ret1);
                    setTimeout(function(){
                        loadWarehouseCodeData()
                        loadBinData(app.searchdata.WarehouseCode)
                        $('#vendorselect').val(app.searchdata.WarehouseCode).trigger("change");
                        $('#vendorselect2').val(app.searchdata.BinNum).trigger("change");
                    },200)
                    console.log(JSON.stringify(app.list),55555)
                    
                    if (app.list.length > 0) {
                        app.receipt_btn = false;
                    }
                }

            }else{
                api.toast({
                    msg: lan['Part_valid_placeholder'],
                    location: 'middle'
                });
            }

        });
    }
    async function loadWarehouseCodeData() {
        userinfo = get_user_info();
        if (!userinfo.Token) {
            return;
        }
        $('.myselect1').selectpicker('destroy'); // 先销毁
        app.WareHouseCodeList = [];
        await api.ajax({
            url: server + 'BaqSvc/WMS_WarehouseForPart/?CompID=' + userinfo.Company + "&Site=" + userinfo.Site +"&PartNum="+app.list[0].PartNum,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {}
        }, function (ret, err) {
            if (ret && ret.value.length > 0) {
                app.WareHouseCodeList = app.WareHouseCodeList.concat(ret.value)
                setTimeout(function () {
                    $('.myselect1').selectpicker('refresh');//在更新
                }, 200)
                console.log(JSON.stringify(app.WareHouseCodeList), 22222)
            }
        });
    }
    function loadOnhandData(){
        userinfo = get_user_info();
        var filter = "?CompID=" + userinfo.Company  + "&Site=" + userinfo.Site;
        filter += "&PartNum=" + app.searchdata.PartNum;
        filter += "&WhseCode=" + app.searchdata.WarehouseCode;
        filter += "&Bin=" + app.searchdata.BinNum;
        if(app.searchdata.LotNum){
            filter += "&LotNum=" + app.searchdata.LotNum;
        }
        console.log(filter,77777)
        api.ajax({
            url: server + 'BaqSvc/WMS_PartBinOnhand/' + filter,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {}  
        }, function (ret, err) {
            ajaxing = 0;
            is_scan = 0;
            console.log(JSON.stringify(ret),66666)
            hideProgress();
            if (ret && ret.value.length>0) {
                app.searchdata.MaxQty = processNumber(ret.value[0].PartBin_OnhandQty,app.searchdata.NumOfDec)  
                app.exist_btn = true;
            }else{
                app.exist_btn = false;
            }
        })
    }    
    async function loadBinData(value) {
        userinfo = get_user_info();
        app.BinNumList = []
        $('.myselect2').selectpicker('destroy'); // 先销毁
        await api.ajax({
            url: server + 'BaqSvc/WMS_WhseBin/?CompID=' + userinfo.Company + "&WarehouseCode=" + value,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {

            }
        }, function (ret, err) {
            if (ret && ret.value.length > 0) {
                app.BinNumList = app.BinNumList.concat(ret.value)
                setTimeout(function () {
                    $('.myselect2').selectpicker('refresh');//在更新
                }, 200)
                console.log(JSON.stringify(app.BinNumList), 22222)
            }

        });
    }
    //批次属性接口
    function LotAttributeOption() {
        api.ajax({
            url: server + 'BaqSvc/WMS_LotAttributeOption/?CompID=' + userinfo.Company + '&PartNum=' + app.searchdata.PartNum + '',
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {}
        }, function (ret, err) {
            ajaxing = 0;
            if (ret && ret.value.length > 0) {
                console.log(JSON.stringify(ret.value[0]), 666666)
                var keys = Object.keys(ret.value[0]);
                app.LotItem = ret.value[0];
                var allN = keys.filter(function (key) {
                    return key !== "Part_Company" && key !== "RowIdent";
                }).every(function (key) {
                    return ret.value[0][key] === "N";
                });
                if (allN) {
                    app.Batch_check = true;
                } else {
                    app.Batch_check = false;
                }

            }

        });
    }

     //关闭取消事件
     function close_win1() {
        api.confirm({
            title: lan['Tips'],
            msg: lan['attribute_cancel_tips'],
            buttons: [lan['NO'], lan['YES'], lan['Cancel']]
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (index == 2) {
                checksubmit();
            } else if (index == 1) {
                close_win();
            }
        });

    }
    function init_list(data) {
        var ret = [];
        for (i in data) {
            data[i].PartNum = data[i].Part_PartNum;
            data[i].PartDescription = data[i].Part_PartDescription;
            data[i].NumOfDec = data[i].UOM_NumOfDec;
            data[i].IUM = data[i].Part_IUM
            data[i].WarehouseCode = data[i].PlantConfCtrl_DefaultWhse;
            data[i].BinNum = data[i].PlantConfCtrl_DefGenBin
            data[i].OnhandQty = 0;
            data[i].is_Lot = -1; //批号判断 -1 未查询  1 需创建 2 不需创建
            data[i].is_SerialNum = -1; //序列号判断 -1 未查询  1 需创建 2 不需创建
            if (data[i].Part_TrackLots) {
                data[i].is_Lot = 1
            } else {
                data[i].is_Lot = 2
            }
            if (data[i].Part_TrackSerialNum) {
                data[i].is_SerialNum = 1; 
            } else {
                data[i].is_SerialNum = 2; 
            }
            data[i].SerialNum = [];
            ret.push(data[i]);

        }
        return ret;
    }
    function init_select() {
        $('.myselect1').selectpicker();
        $('.myselect2').selectpicker();
    }
    function init_select2() {
        app.reason = []
        let filter = "Company eq '" + userinfo.Company + "' and ReasonType eq 'M' ";
        api.ajax({
            url: server + 'Erp.BO.ReasonSvc/List/',
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {
                values: {
                    '$select': 'ReasonCode,Description,Company',
                    '$filter': filter
                }
            }
        }, function (ret, err) {
            console.log(JSON.stringify(ret),11111)
            if (ret && ret.value.length>0) {
                app.reason = app.reason.concat(ret.value)
                setTimeout(function () {
                    $('.myselect3').selectpicker('refresh');//在更新
                }, 200)
            }

        });
        
        

      
    }

    function scan() {
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    // alert(ret.content);
                    app.searchdata.PartNum = ret.content
                    getPartNumInfo(ret.content)
                }

            } else {
                //alert(JSON.stringify(err));
            }
        });
    }

    function checksubmit() {
        if(!app.searchdata.ReasonCode){
            api.toast({
                msg: lan['REASON_CODE_placeholder'],
                location: 'middle'
            });
            return;
        }
        if(!app.searchdata.OnhandQty){
            api.toast({
                msg: lan['Qty_Ament_placeholder'],
                location: 'middle'
            });
            return;
        }
        if(app.searchdata.is_Lot && !app.searchdata.LotNum){
            api.toast({
                msg: lan['LotNum_placeholder'],
                location: 'middle'
            });
            return;
        }
        if(!app.attribute_btn && !app.Batch_check && !app.exist_btn){
            api.toast({
                msg: lan['Lot_Attribute_placeholder'],
                location: 'middle'
            });
            hideProgress();
            return false; 
        }
        if(app.searchdata.is_SerialNum && app.searchdata.SerialNum.length == 0){
            api.toast({
                msg: lan['Serialnum_placeholder'],
                location: 'middle'
            });
            hideProgress();
            return false; 
        }
        console.log(JSON.stringify(app.searchdata),44444)
        let OnhandQty = 0;
        if(processNumber(app.searchdata.OnhandQty,app.searchdata.NumOfDec) < 0){
            OnhandQty =Math.abs(processNumber(app.searchdata.OnhandQty,app.searchdata.NumOfDec))
            if (app.searchdata.PartClass_NegQtyAction == "Stop") {
                
                if (OnhandQty > processNumber(app.searchdata.MaxQty,app.searchdata.NumOfDec)) {
                    const message = `Part: ${app.searchdata.PartNum}. Warehouse: ${app.searchdata.WarehouseCode}. Bin: ${app.searchdata.BinNum}. This transaction will result in a negative onhand quantity for the bin.`;
                    api.confirm({
                        title: lan["Tips"],
                        msg: message,
                        buttons: ["", lan["YES"]],
                    },function (ret, err) {
                        // 用户点击了 "YES"，继续提交数据或执行相应的操作
                        // 在这里编写用户点击 "YES" 后的处理逻辑
                        });
                return
                }else{
                    submitfrom()
                }
            }else if (app.searchdata.PartClass_NegQtyAction == "Warn" ) {
                
                if (OnhandQty > processNumber(app.searchdata.MaxQty,app.searchdata.NumOfDec)) {
                    const message = `This transaction will result in a negative onhand quantity for Part: ${app.searchdata.PartNum}, Bin: ${app.searchdata.BinNum}. Do you want to continue?`;
                    api.confirm(
                    {
                        title: lan["Tips"],
                        msg: message,
                        buttons: [lan["NO"], lan["YES"], lan["Cancel"]],
                    },
                    function (ret, err) {
                        var index = ret.buttonIndex;
                        if (index === 2) {
                            submitfrom();
                            // 用户点击了 "YES"，继续提交数据或执行相应的操作
                            // 在这里编写用户点击 "YES" 后的处理逻辑
                        } else if (index === 1) {
                            close_win();
                            // 用户点击了 "NO"，返回原页面或执行相应的操作
                            // 在这里编写用户点击 "NO" 后的处理逻辑
                        }
                    }
                    );
                    return; // 提示一次后停止继续检查
                }else{
                    submitfrom()
                }
            }else{
                    submitfrom()
            }
        }else{
            submitfrom()
        }
     
        

    }
    function submitfrom() {
       
        postlist = [];

        if(ajaxing){return;}showProgress(lan['Loading']);
        console_debug(app.list, 'submitfrom');
        postlist.push(app.searchdata);

        var postrows = [];
        for (let i in postlist) {
            var item = postlist[i];
            //submit_transfer(data1, app.list[i]);

            var row = {
                "CompanyID": userinfo.Company,
                "PlantID": userinfo.Site,
                "UserName": userinfo.Name,
                "Password": userinfo.password,
                "TranDate": app.searchdata.ArrivedDate,
                "PartNum": app.searchdata.PartNum,
                "WarehouseCode": app.searchdata.WarehouseCode,
                "BinNum": app.searchdata.BinNum,
                "Quantity": app.searchdata.OnhandQty,
                "InvAdjReason":app.searchdata.ReasonCode,
                "LotNum": app.searchdata.LotNum,
                "IUM": app.searchdata.IUM,
            }
            
            var arr = [];
            if(postlist[i].SerialNum.length>0){
                var SerialNum = postlist[i].SerialNum;
                for(k in SerialNum){
                    arr.push(SerialNum[k]);
                }
            }
            if(arr.length>0){
                if(app.searchdata.OnhandQty > 0){
                    row.SelectedSerialNumbers = app.searchdata.data
                }else{
                    let SelectedSerialNumbers = {
                        SelectedSerialNumbers:app.searchdata.SerialNum
                    }
                    row.SelectedSerialNumbers  = SelectedSerialNumbers
                }
                
            }
            postrows.push(row);
        }
        // return
        console.log(JSON.stringify(postrows),111111)
        // return
        let data = [];
        for (i in postrows) {
            submit_transfer(postrows[i], i);
        } 
        
    }


    function submit_transfer(item,ind) {
        let index = []
        api.ajax({
            url: wmsserver + 'invqtyadj/',
            method: 'post',
            returnAll: false,
            headers: {
                'token': wmstoken,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {
                body: create_submit_data(item)
            }
        }, function (ret, err) {
            ajaxing = 0;
            console_debug(ret, err);
            console.log(JSON.stringify(ret),11111)
            console.log(JSON.stringify(err),22222)
            if (ret && ret.code == 1) {
                hideProgress();
                api.alert({
                    title: lan['Tips'],
                    msg: lan['Submitted_successfully']
                }, function (ret, err) {
                    app.receipt_btn = true;
                    app.print_btn = false;
                    app.searchdata.Lot_btn = true;
                    app.searchdata.Description = $('#reasonSelect option:selected').attr("data-name");
                    $('.myselect3').selectpicker('destroy'); // 先销毁
                    $('.myselect4').selectpicker('refresh');//在更新
                });
                
            } else {
                hideProgress();
                app.receipt_btn = false;
                app.searchdata.Lot_btn = false;
                app.print_btn = true;
                errMassage(ret.msg)
            }

        });
    }

</script>

</html>